package com.xz.bigsoubackend.datasource;

import com.xz.bigsoubackend.model.enums.SearchTypeEnum;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xuzhou
 * @version 1.0
 * @createTime 2024-11-11
 * @description
 */
@Component
public class SearchDataSourceRegistry {

    @Resource
    private PictureSearchDataSource pictureSearchDataSource;
    @Resource
    private UserSearchDataSource userSearchDataSource;
    @Resource
    private PostSearchDataSource postSearchDataSource;

    private Map<String, SearchDataSource<T>> searchDataSourceMap;

    @PostConstruct
    public void doInit() {
        searchDataSourceMap = new HashMap() {
            {
                put(SearchTypeEnum.POST.getValue(), postSearchDataSource);
                put(SearchTypeEnum.USER.getValue(), userSearchDataSource);
                put(SearchTypeEnum.PICTURE.getValue(), pictureSearchDataSource);
            }
        };
    }

    public SearchDataSource<T> getSearchDataSourceByType(String type) {
        if (type == null) {
            return null;
        }
        return searchDataSourceMap.get(type);
    }
}
